<?php

/* 属性 attribute */
class Auth_carModel extends BaseModel
{
	var $table  = 'auth_car';
	var $prikey = 'a_actid';
	var $_name  = 'auth_car';

	/**
	 * 获取认证数据
	 * $type  0 实名认证	1 车辆认证 2 运营商认证
	 * @param unknown_type $user_id  用户编号
	 * @param unknown_type $type     认证类型
	 */
	function getAuth($user_id,$type) {
	if (!$user_id)
        {
            $this->_error('no_such_user');
            return false;
        }
        if($type!=2){
		$auth=$this->find("a_userid=$user_id and a_type=$type");
        }else{
        	$auth=$this->getAll("select * from zys_auth left join zys_operator on o_code=a_operator_code where a_userid=$user_id and a_type=$type");
        }
		$list=array();
		if(!empty($auth)){
			foreach($auth as $k=>$v){
				$pic=$this->getRelatedData('has_pic',$v['a_tid']);
				if(!empty($pic)){
					foreach($pic as $k=>$pv){
						$v['pics'][]=$pv;
					}
				}
				$list[]=$v;
			}
		}
		return $list;
	}

	/**
	 * 检测实名认证
	 * @param unknown_type $userid
	 * @param unknown_type $usrname
	 */
	function autonymAuth($userid){
	if (!$userid)
        {
           // $this->_error('no_such_user');
            return false;
        }
		return $this->get("a_userid=$userid and a_type=0");
	}
	/**
	 * 检测车辆认证
	 * @param unknown_type $userid
	 * @param unknown_type $vhccode
	 */
	function vhcAuth($userid){
		return $this->get("a_userid=$userid and a_type=1 ");
	}
	/**
	 * 检测运营商认证
	 * @param unknown_type $userid
	 * @param unknown_type $vhccode
	 */
	function operatorAuth($userid,$code){
		if(empty($code)){
			return $this->get("a_userid=$userid and a_type=2");
		}
		return $this->get("a_userid=$userid and a_type=2 and a_operator_code='$code'");
	}
	
	
	function authStatus($userid){
		$list=array();
		$rnt=$this->get("a_userid=$userid and a_type=0 and ifnull(a_authed,0)=1");
		$list['auth_real']=!empty($rnt);
		$rnt=$this->get("a_userid=$userid and a_type=1 and ifnull(a_authed,0)=1");
		$list['auth_vhc']=!empty($rnt);
		$rnt=$this->get("a_userid=$userid and a_type=2 and ifnull(a_authed,0)=1");
		$list['auth_operator']=!empty($rnt);
		return $list;
	}
}

?>